//index.js
const interfaces = require('../../utils/request.js');

Page({
  data: {
    banner: [],
    brandList: [],
    channel: [],
    hotGoods: [],
    newCategoryList: [],
    newGoods: [],
    topicList: []
  },
  onLoad: function (options) {
    // 页面创建时执行
    const self = this;
    wx.showLoading({
      title: '',
    })
    wx.request({
      url: interfaces.homepage,
      header: {
        'content-type': 'application/json'
      },
      success(res){
        //console.log(res)
        wx.hideLoading()
        self.setData({
          banner: res.data.banner,
          brandList: res.data.brandList,
          channel: res.data.channel,
          newGoods: res.data.newGoods,
          hotGoods: res.data.hotGoods,
          topicList: res.data.topicList,
          newCategoryList: res.data.newCategoryList
        })
      }
    })
  },
  toChannel(e){
    //console.log(e)
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/categorylist/categorylist?id='+id
    })
  },
  branddetail(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/branddetail/branddetail?id='+id
    })
  },
  tobrandlist(){
    wx.navigateTo({
      url: '/pages/brandlist/brandlist',
    })
  },
  newList(e){
    let info = e.currentTarget.dataset.new;
      wx.navigateTo({
        url: "/pages/newgoods/newgoods?isNew=" + 1,
      })
  },
  hotList(e){
    let info = e.currentTarget.dataset.hot;
    wx.navigateTo({
      url: "/pages/hotgoods/hotgoods?isHot=" + 1,
    })
  },
  onShow: function () {
    // 页面出现在前台时执行
  },
  onReady: function () {
    // 页面首次渲染完毕时执行
  },
  onHide: function () {
    // 页面从前台变为后台时执行
  },
  onUnload: function () {
    // 页面销毁时执行
  },
  onPullDownRefresh: function () {
    // 触发下拉刷新时执行
  },
  onReachBottom: function () {
    // 页面触底时执行
  },
  onShareAppMessage: function () {
    // 页面被用户分享时执行
  },
  onPageScroll: function () {
    // 页面滚动时执行
  },
  onResize: function () {
    // 页面尺寸变化时执行
  }

})